﻿<%@ Page Language="C#" MasterPageFile="~/Hero.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Admin_Default" Title="Admin Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <h1 class="mainTitle">Administration</h1>
<h2 class="subTitle">Manage songs</h2>
	<asp:GridView ID="dvSongs" runat="server" AllowPaging="True" 
		AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" 
		DataSourceID="sdsSongs" >
		<Columns>
			<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ControlStyle-ForeColor="#554214"/>
			<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
				ReadOnly="True" SortExpression="ID" />
			<asp:BoundField DataField="Artist" HeaderText="Artist" 
				SortExpression="Artist" />
			<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
			<asp:HyperLinkField DataNavigateUrlFields="ID" 
				DataNavigateUrlFormatString="~/Songs/{0}.zip" HeaderText="Song file" 
				Text="Download" />
		</Columns>
	</asp:GridView>



<h2 class="subTitle">Upload new song</h2>
	<asp:DetailsView ID="dvUpload" runat="server" AutoGenerateRows="False" 
		DataSourceID="sdsSongs" DefaultMode="Insert" CommandRowStyle-ForeColor="#554214">
		<Fields>
			<asp:BoundField DataField="Artist" HeaderText="Artist" 
				SortExpression="Artist" />
			<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
			<asp:TemplateField HeaderText="Song files (ZIP)">
				<InsertItemTemplate>
					<asp:FileUpload ID="fupSongFile" runat="server" />
				</InsertItemTemplate>
			</asp:TemplateField>
			<asp:CommandField ShowCancelButton="False" ShowInsertButton="True" />
		</Fields>
	</asp:DetailsView>
	<%-- 
		HACK:  
			";SELECT @NewID = @@Identity" 
			and 
			<asp:Parameter Direction=Output Name="NewId" Size=4 Type=Int16 />  
			manually added to the code.
			
			Be careful not to remove with the data soruce configuration wizard!
		 --%>
	<asp:SqlDataSource ID="sdsSongs" runat="server" 
		ConflictDetection="CompareAllValues" 
		ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>" 
		DeleteCommand="DELETE FROM [Songs] WHERE [ID] = @original_ID AND [Artist] = @original_Artist AND [Title] = @original_Title" 
		InsertCommand="INSERT INTO [Songs] ([Artist], [Title]) VALUES (@Artist, @Title); SELECT @NewID = @@Identity" 
		OldValuesParameterFormatString="original_{0}" 
		SelectCommand="SELECT * FROM [Songs]" 
		
		UpdateCommand="UPDATE [Songs] SET [Artist] = @Artist, [Title] = @Title WHERE [ID] = @original_ID AND [Artist] = @original_Artist AND [Title] = @original_Title" 
		oninserted="sdsSongs_Inserted" ondeleting="sdsSongs_Deleting">
		<DeleteParameters>
			<asp:Parameter Name="original_ID" Type="Int32" />
			<asp:Parameter Name="original_Artist" Type="String" />
			<asp:Parameter Name="original_Title" Type="String" />
		</DeleteParameters>
		<UpdateParameters>
			<asp:Parameter Name="Artist" Type="String" />
			<asp:Parameter Name="Title" Type="String" />
			<asp:Parameter Name="original_ID" Type="Int32" />
			<asp:Parameter Name="original_Artist" Type="String" />
			<asp:Parameter Name="original_Title" Type="String" />
		</UpdateParameters>
		<InsertParameters>
			<asp:Parameter Name="Artist" Type="String" />
			<asp:Parameter Name="Title" Type="String" />
			<asp:Parameter Direction="Output" Name="NewId" Size="4" Type="Int16" /> 
		</InsertParameters>
	</asp:SqlDataSource>
</asp:Content>

